import 'language_ch.dart';
import 'package:flutter/material.dart';

import 'base_language.dart';
import 'language_en.dart';

/*
 * @desc 国际化
 * 使用eg:GSLocalizations.i18n(context).welcome
 */

class GSLocalizations {

  final Locale locale;

  GSLocalizations(this.locale);

  ///根据不同 locale.languageCode 加载不同语言对应
  static Map<String, BaseLanguage> _localizedValues = {
    'en': new LanguageEn(),
    'zh': new LanguageCh(),
  };

  BaseLanguage get currentLocalized {
    if (_localizedValues.containsKey(locale.languageCode)) {
      return _localizedValues[locale.languageCode];
    }
    return _localizedValues["en"];
  }

  ///通过 Localizations 加载当前的类
   GSLocalizations of(BuildContext context) {
    return Localizations.of(context, GSLocalizations);
  }

  ///通过 Localizations 加载当前的类
  static BaseLanguage i18n(BuildContext context) {
    return (Localizations.of(context, GSLocalizations) as GSLocalizations)
        .currentLocalized;
  }
}